﻿using System.Windows.Controls;
using Infrastructure.Interfaces;
using Infrastructure.ViewModel;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;

namespace Infrastructure.View
{
    public class ViewBase : UserControl, IView
    {
        #region Member variables
        private IUnityContainer unityContainer;
        #endregion

        #region Constructor
        public ViewBase()
        {
        }
        #endregion

        #region Unity container
        [Dependency]
        public IUnityContainer UnityContainer
        {
            get { return this.unityContainer; }
            set
            {
                if (this.unityContainer == value) return;

                this.unityContainer = value;

                var regionManager = this.unityContainer.Resolve<IRegionManager>();
                RegionManager.SetRegionManager(this, regionManager);

                var viewModel = this.unityContainer.Resolve<ViewModelBase>(this.GetType().Name);
                this.DataContext = viewModel;
            }
        }
        #endregion
    }
}
